from datetime import datetime
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
from .extensions import db


class Questionnaire(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    q1 = db.Column(db.String(8))
    q2 = db.Column(db.String(8))
    q3 = db.Column(db.String(8))
    q4 = db.Column(db.String(8))
    q5 = db.Column(db.String(8))
    q6 = db.Column(db.String(8))
    q7 = db.Column(db.String(8))
    q8 = db.Column(db.String(8))
    q9 = db.Column(db.String(512))
    timestamp = db.Column(db.DateTime, default=datetime.utcnow)


class Admin(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32))
    password_hash = db.Column(db.String(128))
    
    def set_password(self, password: str):
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password: str):
        return check_password_hash(self.password_hash, password)
